package com.yuihong.calcu;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    private int mPlusFirst = 0;
    private int mPlusSecond = 0;
    private int mResult = 0;
    private TextView mResultTextView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mResultTextView = (TextView) findViewById(R.id.result);
        mResultTextView.setText("");
    }
    public void onNumberButtonClick(View v) {
        if (!(v instanceof Button)) {
            return;
        }
        Button bt = (Button) v;
        String btText = bt.getText().toString();
        mResultTextView.setText(mResultTextView.getText().toString() + btText);
    }
    public void onPlusButtonClick(View v) {
        Button bt = (Button) v;

        mPlusFirst = new Integer(mResultTextView.getText().toString()).intValue();
        mResultTextView.setText("");
    }
    public void onCalcuButtonClick(View v) {
        Button bt = (Button) v;

        mPlusSecond = new Integer(mResultTextView.getText().toString()).intValue();
        mResult = mPlusFirst + mPlusSecond;
        mResultTextView.setText(new Integer(mResult).toString());
    }
}
